package com.comleader.uap.controller;

import static com.comleader.common.core.web.page.ResultBuilder.getPageResult;
import static com.comleader.uap.common.response.Result.success;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.comleader.common.core.web.page.PageResult;
import com.comleader.uap.common.page.PageQuery;
import com.comleader.uap.common.response.Result;
import com.comleader.uap.pojo.query.CallerProtectQuery;
import com.comleader.uap.pojo.vo.CalledProtectDetailVO;
import com.comleader.uap.pojo.vo.CalledProtectListVO;
import com.comleader.uap.service.CalledProtectPushService;
import com.github.pagehelper.PageHelper;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @Description 被叫/踢线保护
 * @Auhtor 连新景
 * @Date 2024/11/23 17:08
 */
@Api(tags = "被叫&踢线保护")
@Validated
@RestController
@RequestMapping("/called-protect")
public class CalledProtectController {
    @Resource
    private CalledProtectPushService calledProtectPushService;

    /**
     * @Description 分页查询
     * @Auhtor 连新景
     * @Date 2024/11/29 17:53
     * @param query
     * @return com.comleader.uap.common.response.Result<com.comleader.common.core.web.page.PageResult<com.comleader.uap.pojo.vo.CalledProtectListVO>>
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("/list")
    public Result<PageResult<CalledProtectListVO>> list(@Valid @RequestBody PageQuery<CallerProtectQuery> query) {
        PageHelper.startPage(query.getPageNumber(), query.getPageSize());
        return success(getPageResult(calledProtectPushService.selectList(query.getQueryParams())));
    }

    /**
     * @Description 详情
     * @Auhtor 连新景
     * @Date 2024/11/29 17:53
     * @param taskId
     * @param commandId
     * @return com.comleader.uap.common.response.Result<com.comleader.uap.pojo.vo.CalledProtectDetailVO>
     */
    @ApiOperation(value = "详情")
    @GetMapping("/detail")
    public Result<CalledProtectDetailVO> detail(
        @NotBlank(message = "任务ID不能为空") @ApiParam(name = "taskId", value = "任务ID", required = true) @RequestParam String taskId,
        @NotBlank(message = "指令ID不能为空") @ApiParam(name = "commandId", value = "指令ID", required = true) @RequestParam String commandId) {
        return success(calledProtectPushService.selectDetail(taskId, commandId));
    }

    /**
     * @Description 导出
     * @Auhtor 连新景
     * @Date 2024/11/29 17:53
     * @param query
     * @param response
     */
    @ApiOperation(value = "导出")
    @PostMapping("/export")
    public void export(@RequestBody CallerProtectQuery query, HttpServletResponse response) throws IOException {
        calledProtectPushService.export(query, response);
    }

}
